<?php
class QeFileAsset extends QFileAssetBase {
    protected $strTemporaryUploadPath = '/tmp';
    public $File;
    public $Switch=false;
    public $btnDownload;
    //public $btnUpload;
    public $btnTest;

    public $X=0;

    public function __construct($objParentObject, $strControlId = null) {
        parent::__construct($objParentObject, $strControlId);

        // Setup Default Properties
        $this->strTemplate = __APPS_INCLUDE__ . '/controles/QeFileAsset.tpl.php';
        // Setup Default Properties


        /*

        $this->btnUpload->AddAction(new QClickEvent(), new QShowDialogBox($this->dlgFileAsset));
        $this->btnUpload->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'ChangeTabifNeeded'));
        $this->btnUpload->AddAction(new QClickEvent(), new QTerminateAction());

*/
        $this->DialogBoxCssClass = 'fileassetDbox';
        $this->UploadText = QApplication::Translate('Upload');
        $this->CancelText = QApplication::Translate('Cancel');
        $this->btnUpload->Text = '<img src="' . __VIRTUAL_DIRECTORY__ . __IMAGE_ASSETS__ . '/add.png" alt="' . QApplication::Translate('Upload') . '" border="0"/> ' . QApplication::Translate('Upload');
        $this->btnDelete->Text = '<img src="' . __VIRTUAL_DIRECTORY__ . __IMAGE_ASSETS__ . '/delete.png" alt="' . QApplication::Translate('Delete') . '" border="0"/> ' . QApplication::Translate('Delete');
        $this->DialogBoxHtml = QApplication::Translate('<h1>Upload a File</h1><p>Please select a file to upload.</p>');


        // Define the "Delete" Button
        $this->btnDownload = new QLinkButton($this);
        $this->btnDownload->HtmlEntities = false;
        $this->btnDownload->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDownload_Click'));
        $this->btnDownload->AddAction(new QClickEvent(), new QTerminateAction());
        $this->btnDownload->Text = '<img src="' . __APPS_IMG__ . '/download.png" alt="' . QApplication::Translate('DownLoad') . '" border="0"/> ' . QApplication::Translate('DownLoad');
    }
    public function ChangeTabifNeeded() {
        //if ($this->Switch){
        $this->objParentControl->ChangeTabToMe();

        //  $this->Switch = FALSE;
        //}

    }

    public function btnDownload_Click($strFormId, $strControlId, $strParameter) {
        $_SESSION['DIR'] = $this->TemporaryUploadPath;
        $_SESSION['FILE'] = $this->File;
        QApplication::ExecuteJavaScript("window.open('download.php','mywindow','width=400,height=200,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes')");

    }
    public function btnTest_Click($strFormId, $strControlId, $strParameter) {

        $this->objParentControl->ChangeTabToMe();
    }

}
?>